import 'dart:async';
import "package:flutter/material.dart";
import 'package:flutter_demo/utils/sql.dart';
abstract class WidgetInterface {
  int get id;

  //组件英文名
  String get name;

  //组件中文名
  String get cnName;

  //组件截图
  String get image;

  //组件的markdown 文档
  String get doc;

  //类目 id
  int get catId;
}

class WidgetPoint implements WidgetInterface {
  int id;

  ///注意一下 WidgetInterface定义了一系列get的抽象方法，做为WidgetInterface实现类的WidgetPoint因为定义了这些属性,Dart语言都会隐式的定义 setter 方法，针对非空的变量会额外增加 getter 方法

  //组件英文名
  String name;

  //组件中文名
  String cnName;

  //组件截图
  String image;

  // 路由地址
  String routerName;

  //组件markdown 文档
  String doc;

  //组件 demo ，多个以 , 分割
  String demo;

  //类目 id
  int catId;
  final WidgetBuilder buildRouter;

  WidgetPoint(
      {this.id,
      this.name,
      this.cnName,
      this.image,
      this.doc,
      this.catId,
      this.routerName,
      this.buildRouter});

  WidgetPoint.fromJson(Map json)
      : id = json["id"],
        name = json["name"],
        cnName = json["cnName"],
        image = json["image"],
        routerName = json["routerName"],
        doc = json["doc"],
        demo = json["demo"],
        catId = json["catId"],
        buildRouter = json["buildRouter"];

  String toString() {
    return "(WidgetPoint $name)";
  }

  Object toMap() {
    return {
      "id": id,
      "name": name,
      "cnName": cnName,
      "image": image,
      "doc": doc,
      "catId": catId
    };
  }

  Map toSqlCondition() {
    Map _map = this.toMap();
    Map condition = {};

    _map.forEach((k, value) {
      if (value != null) {
        condition[k] = value;
      }
    });

    return condition;
  }
}

class WidgetControlModel {
    final String table = "widget";
    Sql sql;

    WidgetControlModel(){
      sql = Sql.setTable(table);
    }

    ///获取Widget不同条件的列表
    Future<List<WidgetPoint>> getList(WidgetPoint widgetPoint) async {

    }
}
